<template>
  <van-nav-bar title="添加地址" left-text="返回" left-arrow @click-left="goBack" />
  <van-address-edit :area-list="areaList" show-set-default @save="onSave" />
</template>
<script setup>
import { areaList } from "@vant/area-data";
const { cookies } = useCookies();
const router = useRouter();
const LoginUser = reactive(cookies.get("LoginUser"));

const goBack = () => {
  router.go(-1);
};
const onSave = async (val) => {
  let data = {
    busid: LoginUser.id,
    consignee: val.name,
    code: val.areaCode,
    address: val.addressDetail,
    mobile: val.tel,
    status: val.isDefault == true ? "1" : "0",
  };
  let result = await Api.addressAdd(data);
  if (result.code == 1) {
    showNotify({
      type: "success",
      message: result.msg,
      onClose: () => {
        goBack();
      },
    });
  } else {
    showNotify({ type: "danger", message: result.msg });
  }
};
</script>
